// components/myDragonItem/index.js
Component({
    properties: {
        from: {
            type: String,
            default: "list"
        },
        item: {
            type: Object,
            default: () => {
                return {};
            }
        }
    },
    /**
   * 页面的初始数据
   */
    data: {
        operVisible: false,
        animationData: ""
    },
    methods: {
        showOperate: function() {
            let that = this;
            // 显示遮罩层
                        var animation = wx.createAnimation({
                duration: 200,
                timingFunction: "linear",
                delay: 0
            });
            // animation.translateY(150).step()
                        that.setData({
                operVisible: true,
                animationData: animation.export()
            });
            setTimeout(function() {
                animation.translateY(0).step();
                this.setData({
                    animationData: animation.export()
                });
            }.bind(this), 200);
        },
        hideModal: function() {
            // 隐藏遮罩层
            var animation = wx.createAnimation({
                duration: 200,
                timingFunction: "linear",
                delay: 0
            });
            animation.translateY(300).step();
            this.setData({
                animationData: animation.export()
            });
            setTimeout(function() {
                animation.translateY(0).step();
                this.setData({
                    animationData: animation.export(),
                    operVisible: false
                });
            }.bind(this), 200);
        },
        copySubmit: function(e) {
            let id = e.currentTarget.dataset.id;
            this.triggerEvent("confirm", {
                value: id
            });
        },
        endDragon: function(e) {
            let id = e.currentTarget.dataset.id;
            this.hideModal();
            this.triggerEvent("end", {
                value: id
            });
        },
        recommendOper: function(e) {
            let id = e.currentTarget.dataset.id;
            let flag = e.currentTarget.dataset.recommend == 0 ? 1 : 0;
            this.hideModal();
            this.triggerEvent("recommendOper", {
                value: id,
                flag: flag
            });
        },
        startDragon: function(e) {
            let id = e.currentTarget.dataset.id;
            this.hideModal();
            this.triggerEvent("start", {
                value: id
            });
        },
        editDragon: function(e) {
            let id = e.currentTarget.dataset.id;
            this.hideModal();
            this.triggerEvent("edit", {
                value: id
            });
        },
        copyDragon: function(e) {
            let id = e.currentTarget.dataset.id;
            this.hideModal();
            this.triggerEvent("copy", {
                value: id
            });
        },
        /**
     * 接龙详情
     */
        gotoDetail: function() {
            let that = this;
            if (that.from == "paste") {
                return false;
            }
            console.log(that.data.from);
            wx.navigateTo({
                url: `/dragon/pages/dragonDetail/dragonDetail?id=${that.data.item.id}&source=2`
            });
        }
    }
});